<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div class="form-group  col-lg-6">
    <label for="id" class="col-sm-4 control-label">
        验证码:
    </label>
    <div class="col-sm-8">
        <input type="text" id="code" name="code" class="form-control" style="width:250px;"/>
        <img id="imgObj" alt="验证码" src="/imageVerifyC/validateCode.json" onclick="changeImg()"/>
        <a href="#" onclick="changeImg()">换一张</a>
    </div>
</div>

<script type="text/javascript">
    // 刷新图片
    function changeImg() {
        var imgSrc = $("#imgObj");
        var src = "/imageVerifyC/validateCode.json";
        var dataUrl = src+"?timestamp="+new Date().valueOf();
        // imgSrc.attr("src", changeUrl(src));

        imgSrc.attr("src", dataUrl);
    }
    //为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳
    function changeUrl(url) {
        var timestamp = (new Date()).valueOf();
        var index = url.indexOf("?",url);
        if (index > 0) {
            url = url.substring(0, url.indexOf(url, "?"));
        }
        if ((url.indexOf("&") >= 0)) {
            url = url + "×tamp=" + timestamp;
        } else {
            url = url + "?timestamp=" + timestamp;
        }
        return url;
    }
</script>
<script src="../js/jquery-1.10.1.min.js"></script>
</body>

</html>